<template>
  <div id="pictureManagePage" class="picture-manage-container">
    <a-flex justify="space-between">
      <h2>图片管理</h2>

      <a-space>
        <a-button type="primary" href="/add_picture" target="_blank">+ 创建图片</a-button>
        <a-button type="primary" href="/add_picture/batch" target="_blank" ghost>+ 批量创建图片</a-button>
      </a-space>

    </a-flex>
    <div style="margin-bottom: 16px"/>

    <!-- 搜索表单 -->
    <div class="search-form-container">
      <a-form layout="inline" :model="searchParams" @finish="doSearch">
        <a-form-item label="关键词" name="searchText">
          <a-input
            v-model:value="searchParams.searchText"
            placeholder="从名称和简介搜索"
            allow-clear
            @change="handleSearch"
          />
        </a-form-item>
        <a-form-item label="类型" name="category">
          <a-select
            v-model:value="searchParams.category"
            placeholder="请选择类型"
            allow-clear
            show-search
            :filter-option="false"
            @change="handleSearch"
            @search="handleSearchCategoryFilter"
            style="min-width: 150px"
          >
            <a-select-option
              v-for="category in searchFilteredCategories"
              :key="category"
              :value="category"
            >
              {{ category }}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="审核状态" name="reviewStatus">
          <a-select
            v-model:value="searchParams.reviewStatus"
            :options="PIC_REVIEW_STATUS_OPTIONS"
            placeholder="请输入审核状态"
            style="min-width: 180px"
            allow-clear
            show-search
            @change="handleSearch"
            @search="handleSearchTagFilter"
          />
        </a-form-item>

        <a-form-item label="标签" name="tags">
          <a-select
            v-model:value="searchParams.tags"
            mode="multiple"
            placeholder="请选择标签"
            style="min-width: 180px"
            allow-clear
            show-search
            :filter-option="false"
            @change="handleSearch"
            @search="handleSearchTagFilter"
            :max-tag-count="3"
          >
            <a-select-option
              v-for="tag in searchFilteredTags"
              :key="tag"
              :value="tag"
            >
              {{ tag }}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item>
          <a-button type="primary" html-type="submit">搜索</a-button>
          <a-button class="reset-button" @click="handleReset">
            <template #icon>
              <ClearOutlined />
            </template>
            重置
          </a-button>
        </a-form-item>
      </a-form>
    </div>

    <!-- 表格 -->
    <div class="table-container">
      <a-table
        :columns="columns"
        :data-source="dataList"
        :pagination="pagination"
        :loading="loading"
        @change="doTableChange"
        :locale="locale"
        :bordered="true"
        :row-key="(record) => record.id"
        class="picture-table"
      >
        <template #bodyCell="{ column, record }">
          <template v-if="column.dataIndex === 'url'">
            <a-image :src="record.url" :width="120" fallback="" />
          </template>
          <!-- 标签 -->
          <template v-if="column.dataIndex === 'tags'">
            <a-space wrap>
              <a-tag v-for="tag in parseTagsArray(record.tags)" :key="tag" color="blue">
                {{ tag }}
              </a-tag>
            </a-space>
          </template>
          <!-- 图片信息 -->
          <template v-if="column.dataIndex === 'picInfo'">
            <div class="pic-info">
              <div>格式：{{ record.picFormat || '-' }}</div>
              <div>宽度：{{ record.picWidth || '-' }}</div>
              <div>高度：{{ record.picHeight || '-' }}</div>
              <div>宽高比：{{ record.picScale || '-' }}</div>
              <div>大小：{{ formatFileSize(record.picSize) }}</div>
            </div>
          </template>
          <!-- 审核信息 -->
          <template v-if="column.dataIndex === 'reviewMessage'">
            <div>审核状态：{{ PIC_REVIEW_STATUS_MAP[record.reviewStatus] }}</div>
            <div>审核信息：{{ record.reviewMessage }}</div>
            <div>审核人：{{ record.reviewerId }}</div>
          </template>

          <template v-else-if="column.dataIndex === 'createTime'">
            <div class="time-text">
              {{ formatTime(record.createTime) }}
            </div>
          </template>
          <template v-else-if="column.dataIndex === 'editTime'">
            <div class="time-text">
              {{ formatTime(record.editTime) }}
            </div>
          </template>

          <template v-else-if="column.key === 'action'">
            <a-space>
              <a-button
                v-if="record.reviewStatus !== PIC_REVIEW_STATUS_ENUM.PASS"
                type="link"
                @click="showReviewModal(record, PIC_REVIEW_STATUS_ENUM.PASS)"
              >
                通过
              </a-button>
              <a-button
                v-if="record.reviewStatus !== PIC_REVIEW_STATUS_ENUM.REJECT"
                type="link"
                danger
                @click="showReviewModal(record, PIC_REVIEW_STATUS_ENUM.REJECT)"
              >
                拒绝
              </a-button>
              <a-button
                type="link"
                size="small"
                class="edit-button"
                @click="showEditModal(record)"
              >
                <template #icon>
                  <EditOutlined />
                </template>
                编辑
              </a-button>
              <a-popconfirm
                title="确定要删除这张图片吗？"
                ok-text="确定"
                cancel-text="取消"
                @confirm="doDelete(record.id)"
              >
                <a-button
                  type="link"
                  danger
                  size="small"
                  class="delete-button"
                >
                  <template #icon>
                    <DeleteOutlined />
                  </template>
                  删除
                </a-button>
              </a-popconfirm>
            </a-space>
          </template>
        </template>
      </a-table>
    </div>

    <!-- 审核对话框 -->
    <a-modal
      v-model:visible="reviewModalVisible"
      :title="reviewModalTitle"
      @ok="handleReviewSubmit"
      @cancel="handleReviewCancel"
      :confirmLoading="reviewLoading"
      width="500px"
    >
      <a-form
        :model="reviewForm"
        :rules="reviewRules"
        ref="reviewFormRef"
        layout="vertical"
      >
        <a-form-item label="审核原因" name="reviewMessage">
          <a-textarea
            v-model:value="reviewForm.reviewMessage"
            :placeholder="reviewForm.reviewStatus === PIC_REVIEW_STATUS_ENUM.PASS ? '请输入通过原因（可选）' : '请输入拒绝原因'"
            :rows="4"
            :maxlength="200"
            show-count
          />
        </a-form-item>
      </a-form>
      <div class="review-info">
        <p><strong>图片名称：</strong>{{ reviewForm.pictureName }}</p>
        <p><strong>审核操作：</strong>
          <a-tag :color="reviewForm.reviewStatus === PIC_REVIEW_STATUS_ENUM.PASS ? 'green' : 'red'">
            {{ reviewForm.reviewStatus === PIC_REVIEW_STATUS_ENUM.PASS ? '通过' : '拒绝' }}
          </a-tag>
        </p>
      </div>
    </a-modal>

    <!-- 编辑对话框 -->
    <a-modal
      v-model:visible="editModalVisible"
      title="编辑图片"
      @ok="handleEditSubmit"
      @cancel="handleEditCancel"
      :confirmLoading="editLoading"
      width="600px"
    >
      <a-form
        :model="editForm"
        :rules="editRules"
        ref="editFormRef"
        layout="vertical"
        :label-col="{ span: 24 }"
        :wrapper-col="{ span: 24 }"
      >
        <a-form-item label="图片名称" name="name">
          <a-input
            v-model:value="editForm.name"
            placeholder="请输入图片名称"
            :maxlength="100"
            show-count
          />
        </a-form-item>
        <a-form-item label="图片简介" name="introduction">
          <a-textarea
            v-model:value="editForm.introduction"
            placeholder="请输入图片简介"
            :rows="4"
            :maxlength="500"
            show-count
          />
        </a-form-item>
        <a-form-item label="图片类型" name="category">
          <a-select
            v-model:value="editForm.category"
            placeholder="请选择或输入图片类型"
            style="width: 100%"
            :loading="tagCategoryLoading"
            show-search
            allow-clear
            :filter-option="false"
            @search="handleCategorySearch"
            @select="handleCategorySelect"
            @deselect="handleCategoryDeselect"
          >
            <a-select-option
              v-for="category in filteredCategories"
              :key="category"
              :value="category"
            >
              {{ category }}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="图片标签" name="tags">
          <a-select
            v-model:value="editForm.tags"
            mode="tags"
            placeholder="请选择或输入图片标签"
            style="width: 100%"
            :loading="tagCategoryLoading"
            :max-tag-count="10"
            show-search
            allow-clear
            :filter-option="false"
            @search="handleTagSearch"
          >
            <a-select-option
              v-for="tag in filteredTags"
              :key="tag"
              :value="tag"
            >
              {{ tag }}
            </a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
    </a-modal>
  </div>
</template>

<script lang="ts" setup>
import { computed, onMounted, reactive, ref } from 'vue'
import { message } from 'ant-design-vue'
import { SearchOutlined, DeleteOutlined, ClearOutlined, EditOutlined } from '@ant-design/icons-vue'
import {
  deletePictureUsingPost,
  listPictureByPageUsingPost,
  editPictureUsingPost,
  listPictureTagCategoryUsingGet,
  doPictureReviewUsingPost
} from '@/api/pictureController.ts'
import dayjs from 'dayjs'
import { PIC_REVIEW_STATUS_ENUM, PIC_REVIEW_STATUS_MAP, PIC_REVIEW_STATUS_OPTIONS } from '@/constants/picture.ts'

// 添加中文语言配置
const locale = {
  filterTitle: '筛选',
  filterConfirm: '确定',
  filterReset: '重置',
  filterEmptyText: '无筛选项',
  selectAll: '全选当页',
  selectInvert: '反选当页',
  selectionAll: '全选所有',
  sortTitle: '排序',
  expand: '展开行',
  collapse: '关闭行',
  triggerDesc: '点击降序',
  triggerAsc: '点击升序',
  cancelSort: '取消排序',
  emptyText: '暂无数据',
}

// 表格列配置
const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
    width: 80,
    align: 'center',
  },
  {
    title: '图片',
    dataIndex: 'url',
    width: 140,
    align: 'center',
  },
  {
    title: '名称',
    dataIndex: 'name',
    width: 150,
    ellipsis: true,
  },
  {
    title: '简介',
    dataIndex: 'introduction',
    width: 200,
    ellipsis: true,
  },
  {
    title: '类型',
    dataIndex: 'category',
    width: 100,
    align: 'center',
  },
  {
    title: '标签',
    dataIndex: 'tags',
    width: 150,
  },
  {
    title: '图片信息',
    dataIndex: 'picInfo',
    width: 120,
  },
  {
    title: '用户id',
    dataIndex: 'userId',
  },
  {
    title: '审核状态',
    dataIndex: 'reviewMessage',
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 150,
    align: 'center',
  },
  {
    title: '编辑时间',
    dataIndex: 'editTime',
    width: 150,
    align: 'center',
  },
  {
    title: '操作',
    key: 'action',
    width: 150,
    align: 'center',
    fixed: 'right',
  },
]

// 数据相关
const dataList = ref([])
const total = ref(0)
const loading = ref(false)

// 搜索条件
const searchParams = reactive<API.PictureQueryRequest>({
  current: 1,
  pageSize: 10,
  sortField: 'createTime',
  sortOrder: 'descend',
  searchText: '',
  category: '',
  tags: [],
})

// 分页参数
const pagination = computed(() => {
  return {
    current: searchParams.current ?? 1,
    pageSize: searchParams.pageSize ?? 10,
    total: total.value,
    showSizeChanger: true,
    showQuickJumper: true,
    showTotal: (total: number, range: [number, number]) =>
      `第 ${range[0]}-${range[1]} 条，共 ${total} 条`,
    pageSizeOptions: ['10', '20', '50', '100'],
  }
})

// 审核相关状态
const reviewModalVisible = ref(false)
const reviewLoading = ref(false)
const reviewFormRef = ref()
const reviewForm = reactive({
  id: 0,
  pictureName: '',
  reviewStatus: 0,
  reviewMessage: '',
})

// 审核表单验证规则
const reviewRules = computed(() => ({
  reviewMessage: [
    // 只有拒绝时才必填审核原因
    ...(reviewForm.reviewStatus === PIC_REVIEW_STATUS_ENUM.REJECT ? [
      { required: true, message: '请输入拒绝原因', trigger: 'blur' }
    ] : []),
    { max: 200, message: '审核原因不能超过200个字符', trigger: 'blur' }
  ]
}))

// 审核对话框标题
const reviewModalTitle = computed(() => {
  return reviewForm.reviewStatus === PIC_REVIEW_STATUS_ENUM.PASS ? '审核通过' : '审核拒绝'
})

// 显示审核对话框
const showReviewModal = (record: API.Picture, reviewStatus: number) => {
  reviewForm.id = record.id
  reviewForm.pictureName = record.name || '未命名图片'
  reviewForm.reviewStatus = reviewStatus
  reviewForm.reviewMessage = reviewStatus === PIC_REVIEW_STATUS_ENUM.PASS
    ? '符合平台规范，审核通过'
    : ''

  reviewModalVisible.value = true
}

// 取消审核
const handleReviewCancel = () => {
  reviewModalVisible.value = false
  reviewFormRef.value?.resetFields()
}

// 提交审核
const handleReviewSubmit = async () => {
  try {
    await reviewFormRef.value?.validate()
    reviewLoading.value = true

    const res = await doPictureReviewUsingPost({
      id: reviewForm.id,
      reviewStatus: reviewForm.reviewStatus,
      reviewMessage: reviewForm.reviewMessage || (
        reviewForm.reviewStatus === PIC_REVIEW_STATUS_ENUM.PASS
          ? '符合平台规范，审核通过'
          : '不符合平台规范'
      ),
    })

    if (res.data.code === 0) {
      message.success('审核操作成功')
      reviewModalVisible.value = false
      await fetchData()
    } else {
      message.error('审核操作失败：' + (res.data.message || '未知错误'))
    }
  } catch (error) {
    console.error('审核操作失败:', error)
    if (error.errorFields) {
      message.error('请检查表单输入')
    } else {
      message.error('审核操作失败，请稍后重试')
    }
  } finally {
    reviewLoading.value = false
  }
}

// 获取数据
const fetchData = async () => {
  try {
    loading.value = true
    const res = await listPictureByPageUsingPost({
      ...searchParams,
      nullSpaceId:true,
    })
    if (res.data.code === 0 && res.data.data) {
      dataList.value = res.data.data.records ?? []
      total.value = res.data.data.total ?? 0
    } else {
      message.error('获取数据失败：' + (res.data.message || '未知错误'))
      dataList.value = []
      total.value = 0
    }
  } catch (error) {
    console.error('获取数据失败:', error)
    message.error('获取数据失败，请稍后重试')
    dataList.value = []
    total.value = 0
  } finally {
    loading.value = false
  }
}

// 删除图片
const doDelete = async (id: number) => {
  try {
    const res = await deletePictureUsingPost({ id })
    if (res.data.code === 0) {
      message.success('删除成功')
      // 如果当前页没有数据了，回到上一页
      if (dataList.value.length === 1 && searchParams.current > 1) {
        searchParams.current -= 1
      }
      await fetchData()
    } else {
      message.error('删除失败：' + (res.data.message || '未知错误'))
    }
  } catch (error) {
    console.error('删除失败:', error)
    message.error('删除失败，请稍后重试')
  }
}

// 搜索处理
const doSearch = async () => {
  searchParams.current = 1
  await fetchData()
}

// 表格变化处理
const doTableChange = async (page: any, filters: any, sorter: any) => {
  // 处理分页
  searchParams.current = page.current
  searchParams.pageSize = page.pageSize

  // 处理排序
  if (sorter && sorter.field) {
    searchParams.sortField = sorter.field
    searchParams.sortOrder = sorter.order === 'ascend' ? 'ascend' : 'descend'
  }

  await fetchData()
}

// 防抖函数
const debounce = (fn: Function, delay: number) => {
  let timer: any = null
  return function (...args: any[]) {
    if (timer) clearTimeout(timer)
    timer = setTimeout(() => {
      fn.apply(this, args)
    }, delay)
  }
}

// 搜索防抖处理
const handleSearch = debounce(async () => {
  searchParams.current = 1
  await fetchData()
}, 500)

// 重置搜索条件
const handleReset = async () => {
  searchParams.searchText = ''
  searchParams.category = ''
  searchParams.tags = []
  searchParams.current = 1
  // 重置搜索过滤值
  searchCategorySearchValue.value = ''
  searchTagSearchValue.value = ''
  await fetchData()
}

// 编辑相关状态
const editModalVisible = ref(false)
const editLoading = ref(false)
const editFormRef = ref()
const editForm = reactive({
  id: 0,
  name: '',
  introduction: '',
  category: '',
  tags: [] as string[],
})

// 分类和标签数据
const categoryOptions = ref<string[]>([])
const tagOptions = ref<string[]>([])
const tagCategoryLoading = ref(false)

// 编辑表单验证规则
const editRules = {
  name: [
    { required: true, message: '请输入图片名称', trigger: 'blur' },
    { max: 100, message: '图片名称不能超过100个字符', trigger: 'blur' }
  ],
  introduction: [
    { max: 500, message: '图片简介不能超过500个字符', trigger: 'blur' }
  ],
  category: [
    { max: 50, message: '图片类型不能超过50个字符', trigger: 'blur' }
  ],
}

// 获取分类和标签数据
const fetchTagCategory = async () => {
  try {
    tagCategoryLoading.value = true
    const res = await listPictureTagCategoryUsingGet()
    if (res.data.code === 0 && res.data.data) {
      // 提取分类选项
      categoryOptions.value = res.data.data.categoryList || []
      // 提取标签选项
      tagOptions.value = res.data.data.tagList || []
    } else {
      console.warn('获取分类标签失败:', res.data.message)
    }
  } catch (error) {
    console.error('获取分类标签失败:', error)
  } finally {
    tagCategoryLoading.value = false
  }
}

// 显示编辑对话框
const showEditModal = async (record: any) => {
  editForm.id = record.id
  editForm.name = record.name || ''
  editForm.introduction = record.introduction || ''
  editForm.category = record.category || ''
  editForm.tags = parseTagsArray(record.tags)

  // 获取分类和标签数据
  await fetchTagCategory()

  editModalVisible.value = true
}

// 取消编辑
const handleEditCancel = () => {
  editModalVisible.value = false
  // 重置表单和搜索状态
  editFormRef.value?.resetFields()
  categorySearchValue.value = ''
  tagSearchValue.value = ''
}

// 提交编辑表单
const handleEditSubmit = async () => {
  try {
    await editFormRef.value?.validate()
    editLoading.value = true

    const res = await editPictureUsingPost({
      id: editForm.id,
      name: editForm.name,
      introduction: editForm.introduction,
      category: editForm.category,
      tags: editForm.tags,
    })

    if (res.data.code === 0) {
      message.success('更新成功')
      editModalVisible.value = false
      await fetchData()
    } else {
      message.error('更新失败：' + (res.data.message || '未知错误'))
    }
  } catch (error) {
    console.error('更新失败:', error)
    if (error.errorFields) {
      message.error('请检查表单输入')
    } else {
      message.error('更新失败，请稍后重试')
    }
  } finally {
    editLoading.value = false
  }
}

// 工具函数
const parseTagsArray = (tags: string | string[] | null | undefined): string[] => {
  if (!tags) return []
  if (Array.isArray(tags)) return tags
  try {
    const parsed = JSON.parse(tags)
    return Array.isArray(parsed) ? parsed : []
  } catch {
    return []
  }
}

const formatTime = (time: string | number | null | undefined): string => {
  if (!time) return '-'
  return dayjs(time).format('YYYY-MM-DD HH:mm:ss')
}

const formatFileSize = (size: number | null | undefined): string => {
  if (!size || size === 0) return '-'
  if (size < 1024) return `${size}B`
  if (size < 1024 * 1024) return `${(size / 1024).toFixed(2)}KB`
  return `${(size / (1024 * 1024)).toFixed(2)}MB`
}

// 分类和标签搜索过滤
const categorySearchValue = ref('')
const tagSearchValue = ref('')
const searchCategorySearchValue = ref('')
const searchTagSearchValue = ref('')

const filteredCategories = computed(() => {
  if (!categorySearchValue.value) return categoryOptions.value
  return categoryOptions.value.filter(category =>
    category.toLowerCase().includes(categorySearchValue.value.toLowerCase())
  )
})

const filteredTags = computed(() => {
  if (!tagSearchValue.value) return tagOptions.value
  return tagOptions.value.filter(tag =>
    tag.toLowerCase().includes(tagSearchValue.value.toLowerCase())
  )
})

// 搜索表单的分类和标签过滤
const searchFilteredCategories = computed(() => {
  if (!searchCategorySearchValue.value) return categoryOptions.value
  return categoryOptions.value.filter(category =>
    category.toLowerCase().includes(searchCategorySearchValue.value.toLowerCase())
  )
})

const searchFilteredTags = computed(() => {
  if (!searchTagSearchValue.value) return tagOptions.value
  return tagOptions.value.filter(tag =>
    tag.toLowerCase().includes(searchTagSearchValue.value.toLowerCase())
  )
})

// 搜索表单分类过滤处理
const handleSearchCategoryFilter = (value: string) => {
  searchCategorySearchValue.value = value
}

// 搜索表单标签过滤处理
const handleSearchTagFilter = (value: string) => {
  searchTagSearchValue.value = value
}

// 分类搜索处理
const handleCategorySearch = (value: string) => {
  categorySearchValue.value = value
  // 如果输入的值不在选项中，允许自定义输入
  if (value && !categoryOptions.value.includes(value)) {
    editForm.category = value
  }
}

// 分类选择处理
const handleCategorySelect = (value: string) => {
  editForm.category = value
  categorySearchValue.value = ''
}

// 分类取消选择处理
const handleCategoryDeselect = () => {
  categorySearchValue.value = ''
}

// 标签搜索处理
const handleTagSearch = (value: string) => {
  tagSearchValue.value = value
}

// 页面加载时获取数据
onMounted(async () => {
  // 先获取分类和标签数据，用于搜索表单
  await fetchTagCategory()
  // 再获取图片数据
  await fetchData()
})
</script>

<style scoped>
.picture-manage-container {
  padding: 24px;
  background-color: #f0f2f5;
  min-height: 100vh;
}

.search-form-container {
  background-color: #fff;
  padding: 16px 24px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  margin-bottom: 16px;
}

.table-container {
  background-color: #fff;
  padding: 24px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.picture-table {
  margin-top: 16px;
}

.pic-info {
  font-size: 12px;
  line-height: 1.4;
  color: #666;
}

.pic-info > div {
  margin-bottom: 2px;
}

.time-text {
  color: #666;
  font-size: 12px;
}

/* 操作按钮样式修复 */
:deep(.ant-space) {
  flex-wrap: wrap;
}

:deep(.ant-space-item) {
  margin-bottom: 4px;
}

/* 通过和拒绝按钮样式 */
:deep(.ant-btn-link) {
  padding: 4px 8px;
  height: auto;
  line-height: 1.4;
  font-size: 12px;
  border-radius: 4px;
  transition: all 0.3s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
}

:deep(.ant-btn-link:not(.ant-btn-dangerous)) {
  color: #52c41a;
  border: 1px solid transparent;
}

:deep(.ant-btn-link:not(.ant-btn-dangerous):hover) {
  color: #389e0d;
  background-color: #f6ffed;
  border-color: #b7eb8f;
}

:deep(.ant-btn-link.ant-btn-dangerous) {
  color: #ff4d4f;
  border: 1px solid transparent;
}

:deep(.ant-btn-link.ant-btn-dangerous:hover) {
  color: #cf1322;
  background-color: #fff2f0;
  border-color: #ffccc7;
}

/* 编辑按钮样式 */
.edit-button {
  color: #1890ff !important;
  border: 1px solid transparent !important;
  padding: 4px 8px !important;
  height: auto !important;
  line-height: 1.4 !important;
  font-size: 12px !important;
  border-radius: 4px !important;
  transition: all 0.3s !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-width: 48px !important;
  gap: 4px !important;
}

.edit-button:hover {
  color: #096dd9 !important;
  background-color: #e6f7ff !important;
  border-color: #91d5ff !important;
  transform: none !important;
}

/* 删除按钮样式 */
.delete-button {
  color: #ff4d4f !important;
  border: 1px solid transparent !important;
  padding: 4px 8px !important;
  height: auto !important;
  line-height: 1.4 !important;
  font-size: 12px !important;
  border-radius: 4px !important;
  transition: all 0.3s !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-width: 48px !important;
  gap: 4px !important;
}

.delete-button:hover {
  color: #cf1322 !important;
  background-color: #fff2f0 !important;
  border-color: #ffccc7 !important;
  transform: none !important;
}

/* 按钮图标样式 */
:deep(.ant-btn .anticon) {
  font-size: 12px;
}

/* 重置按钮样式 */
.reset-button {
  margin-left: 8px;
  color: #666;
  border-color: #d9d9d9;
  transition: all 0.3s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 15px;
  height: 32px;
  border-radius: 6px;
  font-size: 14px;
  background: linear-gradient(to bottom, #ffffff, #f5f5f5);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.02);
  border: 1px solid #d9d9d9;
}

.reset-button:hover {
  color: #1890ff;
  border-color: #1890ff;
  background: linear-gradient(to bottom, #ffffff, #e6f7ff);
  box-shadow: 0 2px 6px rgba(24, 144, 255, 0.1);
}

.reset-button:active {
  color: #096dd9;
  border-color: #096dd9;
  background: linear-gradient(to bottom, #e6f7ff, #bae7ff);
  box-shadow: 0 1px 2px rgba(24, 144, 255, 0.2);
}

.reset-button :deep(.anticon) {
  font-size: 14px;
  transition: all 0.3s;
  color: #8c8c8c;
}

.reset-button:hover :deep(.anticon) {
  transform: rotate(180deg);
  color: #1890ff;
}

.reset-button:active :deep(.anticon) {
  color: #096dd9;
}

/* 表格样式优化 */
:deep(.ant-table-thead > tr > th) {
  background-color: #fafafa;
  font-weight: 600;
  text-align: center;
}

:deep(.ant-table-tbody > tr:hover > td) {
  background-color: #f5f5f5;
}

:deep(.ant-table-tbody > tr > td) {
  text-align: center;
  vertical-align: middle;
}

:deep(.ant-table-cell) {
  padding: 12px 8px;
}

/* 操作列特殊处理 */
:deep(.ant-table-tbody > tr > td:last-child) {
  padding: 8px 4px;
}

:deep(.ant-table-tbody > tr > td:last-child .ant-space) {
  justify-content: center;
  gap: 4px !important;
}

/* 分页样式 */
:deep(.ant-pagination) {
  margin-top: 16px;
  text-align: center;
}

:deep(.ant-pagination-item-active) {
  border-color: #1890ff;
}

:deep(.ant-pagination-item-active a) {
  color: #1890ff;
}

/* 模态框样式优化 */
:deep(.ant-modal-content) {
  border-radius: 8px;
  overflow: hidden;
}

:deep(.ant-modal-header) {
  background-color: #fafafa;
  border-bottom: 1px solid #f0f0f0;
  padding: 16px 24px;
}

:deep(.ant-modal-title) {
  font-weight: 600;
  color: #262626;
}

:deep(.ant-modal-body) {
  padding: 24px;
}

:deep(.ant-form-item-label > label) {
  font-weight: 500;
  color: #262626;
}

:deep(.ant-input),
:deep(.ant-input-textarea),
:deep(.ant-select-selector) {
  border-radius: 6px;
  border-color: #d9d9d9;
  transition: all 0.3s;
}

:deep(.ant-input:hover),
:deep(.ant-input-textarea:hover),
:deep(.ant-select-selector:hover) {
  border-color: #40a9ff;
}

:deep(.ant-input:focus),
:deep(.ant-input-textarea:focus),
:deep(.ant-select-focused .ant-select-selector) {
  border-color: #1890ff;
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}

/* 图片样式 */
:deep(.ant-image) {
  border-radius: 4px;
  overflow: hidden;
}

/* 标签样式 */
:deep(.ant-tag) {
  margin-bottom: 4px;
  border-radius: 4px;
}

/* 空状态样式 */
:deep(.ant-empty) {
  margin: 40px 0;
}

/* 加载状态样式 */
:deep(.ant-spin-container) {
  min-height: 200px;
}

/* 搜索表单优化 */
:deep(.ant-form-inline .ant-form-item) {
  margin-right: 16px;
  margin-bottom: 16px;
}

:deep(.ant-form-inline .ant-form-item:last-child) {
  margin-right: 0;
}

/* 选择器样式优化 */
:deep(.ant-select-selector) {
  border-radius: 6px;
}

:deep(.ant-select-multiple .ant-select-selection-item) {
  border-radius: 4px;
  background-color: #f0f2f5;
  border-color: #d9d9d9;
}

:deep(.ant-select-multiple .ant-select-selection-item-remove) {
  color: #999;
}

:deep(.ant-select-multiple .ant-select-selection-item-remove:hover) {
  color: #ff4d4f;
}

/* 下拉选项样式 */
:deep(.ant-select-dropdown) {
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

:deep(.ant-select-item-option-selected:not(.ant-select-item-option-disabled)) {
  background-color: #e6f7ff;
  color: #1890ff;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .picture-manage-container {
    padding: 16px;
  }

  .search-form-container,
  .table-container {
    padding: 16px;
  }

  :deep(.ant-form-inline .ant-form-item) {
    margin-bottom: 16px;
  }

  :deep(.ant-table-scroll) {
    overflow-x: auto;
  }

  /* 移动端操作按钮优化 */
  :deep(.ant-space) {
    flex-direction: column;
    align-items: stretch;
    gap: 4px !important;
  }

  :deep(.ant-space-item) {
    width: 100%;
  }

  .edit-button,
  .delete-button,
  :deep(.ant-btn-link) {
    width: 100% !important;
    text-align: center !important;
    justify-content: center !important;
  }
}

/* Popconfirm 样式优化 */
:deep(.ant-popover-content) {
  border-radius: 6px;
}

:deep(.ant-popover-inner-content) {
  padding: 12px 16px;
}

/* 审核信息显示优化 */
.review-info {
  background-color: #f8f9fa;
  border-radius: 6px;
  padding: 16px;
  margin-top: 16px;
  border-left: 4px solid #1890ff;
}

.review-info p {
  margin-bottom: 8px;
  color: #595959;
}

.review-info p:last-child {
  margin-bottom: 0;
}
</style>
